package com.ruoyi.system.Listener;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.TestLeave;
import com.ruoyi.system.mapper.TestLeaveMapper;
import com.warm.flow.core.entity.Instance;
import com.warm.flow.core.listener.Listener;
import com.warm.flow.core.listener.ListenerVariable;
import com.warm.tools.utils.ObjectUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
public class StartListener implements Listener {

    @Resource
    private TestLeaveMapper testLeaveMapper;

    private static final Logger log = LoggerFactory.getLogger(StartListener.class);

    @Override
    public void notify(ListenerVariable variable) {
        log.info("开始监听器");
        Instance instance = variable.getInstance();
        Map<String, Object> variableMap = variable.getVariable();
        if (ObjectUtil.isNotNull(variableMap)) {
            TestLeave testLeave = (TestLeave) variableMap.get("testLeave");
            /** 如果{@link com.ruoyi.system.service.impl.TestLeaveServiceImpl}中更新了，这里就不用更新了*/
//        if (startFlow) {
//            testLeave.setInstanceId(instance.getId());
//            testLeave.setNodeCode(instance.getNodeCode());
//            testLeave.setNodeName(instance.getNodeName());
//            testLeave.setFlowStatus(instance.getFlowStatus());
//            testLeave.setCreateTime(DateUtils.getNowDate());
//            testLeaveMapper.insertTestLeave(testLeave);
//        }
        }

        log.info("开始监听器结束;{}", "开启流程完成");
    }
}
